//
//  Regula.m
//  Flounder
//
//  Created by 筱亮 on 2017/6/22.
//  Copyright © 2017年 Chuangchuang. All rights reserved.
//

#import "Regula.h"

@implementation Regula
+ (BOOL)isMobilePhoneNumber:(NSString *)phoneNum {
    
    if (phoneNum.length != 11) {
        return NO;
    } else {
        NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[0678])\\d{8}$";
        NSString *CM = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\\d{8}$)|(^1705\\d{7}$)";
        NSString *CU = @"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\\d{8}$)|(^1709\\d{7}$)";
        NSString *CT = @"(^1(33|53|77|8[019])\\d{8}$)|(^1700\\d{7}$)";
        
        NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
        NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
        NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
        NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
        
        if (([regextestmobile evaluateWithObject:phoneNum] == YES)
            || ([regextestcm evaluateWithObject:phoneNum] == YES)
            || ([regextestct evaluateWithObject:phoneNum] == YES)
            || ([regextestcu evaluateWithObject:phoneNum] == YES)) {
            
            return YES;
        } else {
            return NO;
        }
    }
}

@end
